<template>
	<view class="container">
		<mescroll-body   @init="mescrollInit" :down="downOption" @down="downCallback" :up="upOption" @up="upCallback">
			<yxylCommonLog :logList="items"></yxylCommonLog>		
			<mescroll-empty v-if="items.length==0"></mescroll-empty>
		</mescroll-body>
	</view>
</template>

<script>
import MescrollBody from 'mescroll-uni/mescroll-body.vue'
import MescrollMixin from "mescroll-uni/mescroll-mixins.js";
import yxylCommonLog from '@/components/yxyl-common-log/yxyl-common-log.vue';
import MescrollEmpty from 'mescroll-uni/components/mescroll-empty.vue';
export default {
	mixins: [MescrollMixin],
	components: { yxylCommonLog, MescrollBody,MescrollEmpty },
	data() {
		return {
			items: [],
			id: '',
			pageName: '',
			commonItem: 0,
			downOption: {
				use: true, // 是否启用下拉刷新; 默认true,
				auto: false,
				native:true
			},
			//上拉加载的常用配置
			upOption: {
				use: true, // 是否启用上拉加载; 默认true
				auto: false, // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
				page: {
					num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					size: 10 // 每页数据的数量,默认10
				},
				noMoreSize: 2, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
				empty: false,
				textNoMore: '---没有了---'
			}
		};
	},
	onShareAppMessage(e) {
		return {
			path: this.$handlerAppMessagePath()
		};
	},
	onLoad(e) {
		this.id = e.Id||'';
		this.commonItem = e.Type;
		this.bindLogs().then(() => {
			// #ifdef H5
			this.$wechat.share({
				link: this.$handlerAppMessagePath()
			});
			// #endif
			if (this.pageName) {
				uni.setNavigationBarTitle({
					title: this.pageName
				});
			}
		});
	},
	methods: {
		async bindLogs() {
			var that = this;

			var result = await this.$http.request({
				url: 'api/CommonPage/GetCommonAll',
				data: {
					Id: that.id,
					CommonItem: that.commonItem,
					SkipCount: that.items.length,
					MaxResultCount: 30
				}
			});
			that.items = that.items.concat(result.items);
			that.pageName = result.title;
			return result.items.length;
		},
		downCallback() {
			this.items = [];
			this.bindLogs()
				.then(() => {
					this.mescroll.endSuccess();
				})
				.catch(() => {
					this.mescroll.endErr();
				});
		},
		async upCallback(page) {
			try {
				var Count = await this.bindLogs();
				this.mescroll.endSuccess(Count, Count > 0);
			} catch (e) {
				// 失败隐藏下拉加载状态
				this.mescroll.endErr();
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.noText {
	width: 100%;
	margin-top: 30rpx;
	text-align: center;
	display: flex;
	justify-content: center;
}
</style>
